<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>コントロールパネル</title>
		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		<script src="assets/scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script src="assets/scripts/table.js" type="text/javascript"></script>
		<link type="text/css" href="./assets/styles/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
		<script type="text/javascript" src="./assets/scripts/ui/ui.core.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.datepicker.js"></script>
		<script type="text/javascript">
		$(function() {
			$('.message').fadeIn("slow");
			/*
			$('.text_date').datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'yy/mm/dd'
			});
			$('#btn-export').click(function(){	
				if(confirm('ダウンロードしますか？')){
					document.fm.csv.value="download";
					document.fm.submit();
				}
			});
			*/
			$('#year4').change(function(){
				var year4 = this.value;
				var myDate = new Date();
				var nowtime =  myDate.getTime();
				$.get("mmap_week_ajax.php",{ y: year4,t : nowtime }, function(data){
					$("#matrix_cd").children().remove();
					$("#matrix_cd").append( data ); 
				});
			});
			
			$('#year4c').change(function(){
				var year4c = this.value;
				var myDate = new Date();
				var nowtime =  myDate.getTime();
				$.get("mmap_week_ajax.php",{ y: year4c,t : nowtime }, function(data){
					$("#matrix_cdc").children().remove();
					$("#matrix_cdc").append( data ); 
				});
			});
			
			$('#btn_search').click(function(){	
				 if ( chkWeek() ) {
					document.fm.csv.value="";
					document.fm.submit();
				 }
			});
			
			$('#btn-export').click(function(){	
				if(confirm('ダウンロードしますか？')){
					document.fm.csv.value="download";
					document.fm.submit();
				}
			});
			
			$('#btn-copy').click(function(){	
				var weekid = $("#matrix_cdc").val() ;
				if (weekid.length == 0){
					alert("コピー週を選択してください");
					return false;
				 }
				if( !confirm('コピーしてよろしいですか？') ){
					return false;
				}
				var weekfrom = document.fm.fweek.value;
				var year4c = $("#year4c").val();
				if (weekfrom==weekid) {
					alert("同じ週のデータはコピーできません");
					return false;
				}
				var myDate = new Date();
				var nowtime =  myDate.getTime();
				var deliveCnt = 0;
				$.get("ajax_delive_exist.php",{ w: weekid,t : nowtime }, function(data){
					deliveCnt = 1 * data;
					 if ( (deliveCnt * 1) > 0 ) {
						if( confirm('該当週のデータは既に存在します、コピーしてもよろしいですか？') ){
							document.fm.tweek.value = weekid;
							document.fm.csv.value = 'copy';
							document.fm.submit();
						}
					 } else {
						document.fm.tweek.value = weekid;
						document.fm.csv.value="copy";
						document.fm.submit();
					 }
				});
				 //document.fm.submit();
			});
			
			$('#btn-reset').click(function(){	
				location.href = document.fm.action;
			});
			
			$('#btn-add').click(function(){	
				 if ( chkWeek() ) {
					 //document.fm.submit();
					 location.href = "mins_delive_form.php?w=" + $("#matrix_cd").val();
				 }
			});
		});
		function toPage(thepage) {
			document.fm.page.value =  thepage;
			document.fm.csv.value="";
			document.fm.submit();
		}
		function chkWeek() {
			var weekid = $("#matrix_cd").val() ;
			if (weekid.length == 0){
				alert("週を選択してください");
				return false;
			 }
			return true;
		}
		</script>
		<link rel="stylesheet" type="text/css" href="./assets/styles/tablesorter.css" />
		<script type="text/javascript" src="./assets/scripts/tablesorter.js"></script>
	</head>
	<body id="">
{{$menu}}
{{$logout}}
		<div id="container"><div class="wrapper">
				<h2>折込販売店マスター管理</h2>
			 <ul class="submenu clearfix">
				<li><a href="minsshop_index.php">折込販売店情報一覧</a></li>
				{{ if (!$isG4) }} <li><a href="minsshop_form.php">折込販売店情報登録</a></li>{{ /if }}
				<li><a href="minsshop_import.php">CSV更新</a></li>
				<li>納品先マスタ</li>
			</ul>
			<h3>納品先マスタ</h3>
			<form name="fm" id="fm" method="get" action="mins_delive_index.php" >
				<input type="hidden" name="page" />
				<table class="formTable">
					<tbody>
<tr>
						<th>※年度.週</th>
							<td>
{{ html_options id='year4' name='year4' options=$year4 selected=$forms.year4 }} 年 &nbsp;&nbsp;{{ $err.year4 }}{{ html_options id='matrix_cd' name='matrix_cd' options=$week  selected=$forms.matrix_cd }}{{ $err.matrix_cd }}
							</td>
						</tr>
						<tr>
							<th>折込会社</th>
							<td>
{{ if ($isG4) }} 
							<input type="text " name="ins_co_name"  class="dtext" value="{{ $forms.ins_co_name }}"  readonly/>
							<input type="hidden" name="ins_co_cd" value="{{ $forms.ins_co_cd }}" />
{{ else }}
							{{ html_options id='ins_co_cd' name='ins_co_cd' options=$ins_co selected=$forms.ins_co_cd }}
{{ /if }}
							</td>
						</tr>
					</tbody>
				</table>
				<p class="button" style="text-align:right">
					<button type="button" id="btn-reset"><span>クリア</span></button>
					<button type="button" id="btn_search" class="submit"><span>絞込検索</span></button>
				</p>
				<input type="hidden" name="search" value="1" />
				<input type="hidden" name="csv" />
				<input type="hidden" name="fweek"  value="{{$forms.matrix_cd}}"/>
				<input type="hidden" name="tweek" />
			</form>
{{ if is_numeric($page.cnt) }}
{{ if $page.cnt > 0 }}
			<p class="message">{{ $page.cnt }}件の情報が見つかりました。</p>
			<p align="left">{{$pageing}}</p>
			<table id="search_result" class="sortable">
				<thead>
					<tr>
						<th><h3>折込会社</h3></th>
						<th><h3>納品先コード</h3></th>
						<th><h3>納品先名</h3></th>
						<th><h3>郵便番号</h3></th>
						<th><h3>住所</h3></th>
						<th><h3>電話番号</h3></th>
						<th><h3>締切日時</h3></th>
						<th><h3>更新日時</h3></th>
						<th><h3>更新者</h3></th>
						<th><h3>操作</h3></th>
					</tr>
				</thead>
				<tbody>
{{ foreach from=$data key=k item=v name="member" }}
					<tr class="{{cycle values=odd,mod name='member'}}">
						<td>{{ $ins_co[$v.ins_co_cd] }}</td>
						<td>{{ $v.delive_cd }}</td>
						<td>{{ $v.delive_name }}</td>
						<td>{{ $v.postcode }}</td>
						<td>{{ $v.address }}</td>
						<td>{{ $v.tel }}</td>
						<td>{{ $v.close_day }} 日前の  {{ $v.close_time }} 時</td>
						<td class="center">{{ $v.u_time|date_format:"%Y-%m-%d %H:%M" }}</td>
						<td >{{ $v.m_user_name }}</td>
						<td class="center"><a href="mins_delive_form.php?w={{ $forms.matrix_cd }}&id={{ $v.id }}">[更新]</a></td>
					</tr>
{{ /foreach }}
				</tbody>
			</table>
			<p align="right">{{$pageing}}</p>
	<p>結果を{{ html_options id='year4c' name='year4c' options=$year4 selected=$forms.year4c }} 年　{{ html_options id='matrix_cdc' name='matrix_cdc' options=$weekc  selected=$forms.matrix_cdc }}週へ<button type="button" id="btn-copy"  ><span>コピー</span></button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ if $copymsg }} {{ $copymsg }}{{/if}}</p>
				<p class="button">
					<button type="button" id="btn-export"  ><span>CSVダウンロード</span></button>
				</p>
				
{{ else }}
<p class="message">条件にマッチする情報は見つかりませんでした。</p>
{{ /if }}
{{ else }}
	<p class="message">ここに検索結果が表示されます。</p>
{{ /if }}
				<p class="button" style="text-align:left">
					<button type="button" id="btn-add"  ><span>新規追加</span></button>
				</p>
		</div></div>
		{{ $footer }}
	</body>
</html>